<script lang="ts" setup>
import { inject } from 'vue'
import { RouterLink } from 'vue-router'

defineProps({
  // 点击面包屑组件跳转的地址
  to: {
    type: String
  }
})

// 组件父组件传递的分隔符
const separator = inject('separator')
</script>

<script lang="ts">
export default { name: 'XtxBreadItem' }
</script>

<template>
  <div class="xtx-bread-item">
    <!-- 跳转地址 -->
    <RouterLink v-if="to" :to="to"><slot /></RouterLink>
    <span v-else><slot /></span>

    <!-- 分隔符 -->
    <i v-if="separator">{{ separator }}</i>
    <i v-else class="iconfont icon-angle-right"></i>
  </div>
</template>

<style lang="scss" scoped>
.xtx-bread-item {
  i {
    margin: 0 6px;
    font-size: 10px;
  }
  // 最后一个i隐藏
  &:nth-last-of-type(1) {
    i {
      display: none;
    }
  }
}
</style>
